package com.zzyl.job;

import com.zzyl.service.CustomerReservationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
public class MyTask {

    @Autowired
    private CustomerReservationService customerReservationService;
    //@Schedule(cron = "* * * 5 * ?") //?周和日不能同时存在------周五的第6日不可能永远都是
    //@Schedule(cron = "1,5,9 * * * * ?") //每月每时每分的第1秒，第5秒，第9秒分别执行
    //@Schedule(cron = "2/10 * * * * ?") //每月每时每分的从2秒开始间隔10秒分别执行
//    @Scheduled(cron = "1-5 * * * * ?")  //每月每时每分的第1，2，3，4，5都执行
//    public void executeTask(){
//        System.out.println("asasf-----" + LocalDateTime.now());
//    }

    /**
     * 定时任务 每隔30分钟触发一次
     */
    @Scheduled(cron = "0 1,31 8-18 * * ?")
    public void executeTask(){
        customerReservationService.expireReservation(LocalDateTime.now().plusHours(-1));
        log.info("定时任务开始执行," + LocalDateTime.now() + "之前的预约已过期");
    }
}


















